<template>
  <!-- 安防-累计数据 security-accumulate -->
  <div class="security-accumulate chart-box1">
    <div class="chart-title">累计数据</div>
    <div class="chart-content" align="middle">
      <a-row align="middle" :gutter="0" style="width: 100%; height: 100%">
        <!-- <a-col :span="12" class="accumulate-col">
          <div class="accumulate-item">
            <span>累计告警数：</span>
            <CountTo :start-val="1" :end-val="20" :duration="3000" />
          </div>
        </a-col>
        <a-col :span="12" class="accumulate-col">
          <div class="accumulate-item">
            <span>累计故障数：</span>
            <CountTo :start-val="1" :end-val="20" :duration="3000" />
          </div>
        </a-col>
        <a-col :span="12" class="accumulate-col">
          <div class="accumulate-item">
            <span>今日告警数：</span>
            <CountTo :start-val="1" :end-val="20" :duration="3000" />
          </div>
        </a-col>
        <a-col :span="12" class="accumulate-col">
          <div class="accumulate-item">
            <span>今日故障数：</span>
            <CountTo :start-val="1" :end-val="20" :duration="3000" />
          </div>
        </a-col> -->
        <a-col
          :span="12"
          class="accumulate-col"
          v-for="(item, index) of list"
          :key="index"
        >
          <div class="accumulate-item">
            <div class="number">
              <CountTo :start-val="1" :end-val="item.value" :duration="3000" />
              <span class="unit"> 次 </span>
            </div>
            <div>{{ item.label }}</div>
          </div>
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, toRefs, watch } from "vue";
import CountTo from "../countTo/index.vue";
import common from "../../utils/common";
import request from "../../../../common/utils/request";
import store from "../../../../store";

export default defineComponent({
  name: "SecurityAccumulate",
  components: { CountTo },
  setup(props) {
    let keyCount = 1;
    const state = reactive({
      chartKey: `current_peak_${keyCount}`,
      data: {
        count: {
          ...common.countToInit,
        },
      },
      list: [],
    });

    watch(
      () => store.getters.security.AlarmTotal,
      (val) => {
        if (val) {
          getData();
        }
      }
    );

    const getData = () => {
      const { AlarmTotal } = store.getters.security;
      if (AlarmTotal && AlarmTotal.length) {
        state.list = AlarmTotal;
        console.log(" state.list", state.list);
        state.list.forEach((item) => {
          item.oldVal = state.data.count.newVal;
          item.newVal = item.value;
        });
      }
    };
    getData();

    return {
      ...toRefs(state),
    };
  },
});
</script>
<style lang="less" scoped>
@import "../../styles/common.less";

.accumulate-col {
  height: 100%;
  padding: 0.5rem 0.8rem;

  .accumulate-item {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0.4rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 1.6rem;

    .number {
      color: rgb(220, 106, 31);
      font-size: 2.8rem;
      font-weight: bold;
    }

    .unit {
      font-size: 1.8rem;
      margin-left: 0.4rem;
    }
  }
}
</style>
